package com.saodisheng.service.impl;

import com.jfinal.plugin.activerecord.Page;
import com.saodisheng.model.Posts;
import com.saodisheng.service.AccountService;
import com.saodisheng.service.QuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 *
 * @author 扫地生_saodisheng
 * @date 2022/1/28
 */
@Service
public class QuestionServiceIImpl implements QuestionService {
	@Autowired
	private AccountService accountService;

	final Posts postDao = new Posts().dao();
	int pageSize = 20;
	
	@Override
	public Page<Posts> getQuestions(int pageNum) {
		String select = "select * ";
		String from = "from posts where post_type=4 and status=? order by createAt desc";
		
		Page<Posts> postPage = postDao.paginate(pageNum, pageSize, select, from, Posts.STATUS_PUB);
		accountService.join("userId", postPage.getList(), "nickName", "avatar");
		
		return postPage;
	}
	
	@Override
	public Page<Posts> getHotQuestions(int pageNum) {
		String select = "select * ";
		String from = "from posts where post_type=4 and status=? order by views desc";
		Page<Posts> postPage = postDao.paginate(pageNum, pageSize, select, from, Posts.STATUS_PUB);
		
		accountService.join("userId", postPage.getList(), "nickName", "avatar");
		
		return postPage;
	}
}
